# -*- coding: utf-8 -*-
from sqlalchemy.orm import Session
from .model import CustomerInformation

def get_customer(db: Session, customer_id: int):
    return db.query(CustomerInformation).filter(CustomerInformation.id == customer_id).first()

def get_customers(db: Session, skip: int = 0, limit: int = 100):
    return db.query(CustomerInformation).offset(skip).limit(limit).all()

def create_customer(db: Session, customer: CustomerInformation):
    db.add(customer)
    db.commit()
    db.refresh(customer)
    return customer

# 评分
def rate_customer(db: Session, customer_id: int, rating: float):
    customer = get_customer(db, customer_id)
    if customer:
        customer.rating = rating
        db.commit()
        db.refresh(customer)
        return customer
    else:
        return None